package com.qdsg.ysg.doctor.ui.fragment;//package com.qdsg.ysg.doctor.ui.fragment;
//
//import android.graphics.Canvas;
//import android.graphics.Rect;
//import android.os.Bundle;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.TextView;
//
//import com.rest.business.RestProxy;
//import com.rest.response.LoginResponse;
//import com.rest.response.Patient;
//import com.rest.response.ReferralResponse;
//import com.scwang.smartrefresh.layout.api.RefreshLayout;
//import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
//import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
//import com.scwang.smartrefresh.layout.header.ClassicsHeader;
//import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
//import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import butterknife.BindView;
//import butterknife.OnClick;
//import io.reactivex.Observer;
//import io.reactivex.disposables.Disposable;
//import jz.joyoung.robot.util.PreferencesHelper;
//import com.qdsg.ysg.doctor.R;
//import com.qdsg.ysg.doctor.base.BaseApplication;
//import com.qdsg.ysg.doctor.base.BaseFragment;
//import com.qdsg.ysg.doctor.ui.AddReferralActivity;
//import com.qdsg.ysg.doctor.ui.PatientDetailActivity;
//
///**
// * Created by Administrator on 2018/5/25.
// */
//
//public class ReferralFragment extends BaseFragment {
//
//    private static ReferralFragment referralFragment;
//
//    @BindView(R.id.refreshLayout)
//    RefreshLayout refreshLayout;
//    @BindView(R.id.recyclerView)
//    RecyclerView recyclerView;
//    @BindView(R.id.btn_referral)
//    TextView btn_referral;
//
//    MyAdapter adapter;
//
//    List<Patient> list = new ArrayList<>();
//
//    public static ReferralFragment newInstance() {
//        if (referralFragment == null) {
//            referralFragment = new ReferralFragment();
//            return referralFragment;
//        } else {
//            return referralFragment;
//        }
//    }
//
//    @Override
//    protected int getLayoutResource() {
//        return R.layout.fragment_referral;
//    }
//
//    @Override
//    protected void initView() {
//        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        recyclerView.setLayoutManager(manager);
//        adapter = new MyAdapter();
//        recyclerView.setAdapter(adapter);
//        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
//            @Override
//            public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
//                super.onDraw(c, parent, state);
//            }
//
//            @Override
//            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//                super.getItemOffsets(outRect, view, parent, state);
//                outRect.bottom = 1;
//            }
//        });
//        refreshLayout.setRefreshFooter(new BallPulseFooter(getActivity()).setSpinnerStyle(SpinnerStyle.Scale));
//        refreshLayout.setRefreshHeader(new ClassicsHeader(getActivity()));
//        refreshLayout.setEnableLoadMore(false);
//        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
//            @Override
//            public void onRefresh(RefreshLayout refreshlayout) {
//                if (BaseApplication.userType == 1) {
//                    getReferralBaseList();
//                } else if (BaseApplication.userType == 2) {
//                    getReferralProList();
//                }
//            }
//        });
//        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
//            @Override
//            public void onLoadMore(RefreshLayout refreshlayout) {
//
//            }
//        });
//        if (BaseApplication.userType == 1) {
//            btn_referral.setVisibility(View.VISIBLE);
//        } else if (BaseApplication.userType == 2) {
//            btn_referral.setVisibility(View.GONE);
//        }
//
//    }
//
//    @Override
//    protected void initData() {
////        if (BaseApplication.userType == 1) {
////            getReferralBaseList();
////        } else if (BaseApplication.userType == 2) {
////            getReferralProList();
////        }
//    }
//
//    class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
//
//        @Override
//        public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
//            Holder myHolder = new Holder(LayoutInflater.from(getActivity()).inflate(R.layout.item_referral, parent, false));
//            return myHolder;
//        }
//
//        @Override
//        public void onBindViewHolder(Holder holder, final int position) {
//            holder.itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    Bundle bundle = new Bundle();
//                    bundle.putInt("type", 0);
//                    bundle.putSerializable("obj", list.get(position));
//                    startActivity(PatientDetailActivity.class, bundle);
//                }
//            });
////            holder.tv_reason.setText(list.get(position).referralCont);
////            holder.tv_time.setText(list.get(position).bookDt);
////            holder.tv_hospital.setText(list.get(position).hosNameBase);
//            holder.tv_patient_name.setText(list.get(position).patientName);
//        }
//
//        @Override
//        public int getItemCount() {
//            return list.size();
//        }
//
//        class Holder extends RecyclerView.ViewHolder {
//
//            TextView tv_reason, tv_time, tv_hospital, tv_patient_name;
//
//            public Holder(View itemView) {
//                super(itemView);
//                tv_reason = itemView.findViewById(R.id.tv_reason);
//                tv_time = itemView.findViewById(R.id.tv_time);
//                tv_hospital = itemView.findViewById(R.id.tv_hospital);
//                tv_patient_name = itemView.findViewById(R.id.tv_patient_name);
//            }
//        }
//
//    }
//
//
//    @Override
//    public void onResume() {
//        if (BaseApplication.userType == 1) {
//            getReferralBaseList();
//        } else if (BaseApplication.userType == 2) {
//            getReferralProList();
//        }
//        super.onResume();
//    }
//
//    @OnClick(R.id.btn_referral)
//    void btn_referral() {
//        Bundle bundle = new Bundle();
//        bundle.putInt("type", 0);
//        startActivity(AddReferralActivity.class, bundle);
//    }
//
//    private void getReferralBaseList() {
//        RestProxy.getInstance().getReferralBaseList(PreferencesHelper.getInstance().getString(getActivity(), "username"), PreferencesHelper.getInstance().getString(getActivity(), "id"), new Observer<ReferralResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(ReferralResponse referralResponse) {
//                list.clear();
//                list.addAll(referralResponse.data);
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//        });
//    }
//
//    private void getReferralProList() {
//        RestProxy.getInstance().getReferralProList(PreferencesHelper.getInstance().getString(getActivity(), "username"), PreferencesHelper.getInstance().getString(getActivity(), "id"), new Observer<ReferralResponse>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//
//            }
//
//            @Override
//            public void onNext(ReferralResponse referralResponse) {
//                list.clear();
//                list.addAll(referralResponse.data);
//                adapter.notifyDataSetChanged();
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//
//            @Override
//            public void onComplete() {
//                refreshLayout.finishLoadMore(true/*,false*/);//传入false表示加载失败
//                refreshLayout.finishRefresh(true/*,false*/);//传入false表示加载失败
//            }
//        });
//    }
//
//}
